package com.yxym.interclass;
//演示匿名内部类
public class AnonymousInnerClass {
    public static void main(String[] args) {
        Outer04 outer04 = new Outer04();
        outer04.method();
    }
}

class Outer04{//外部类
    private int n1 = 10;
    public void method(){
//        A tiger = new Tiger();
//        tiger.say();
        //1.实用接口创建对象，
        //2.某个类只是用一次，后面不在使用
        //3.可以使用匿名内部类来简化开发
        A tiger = new A() {
            //4.编译类型接口A，运行类型匿名内部类!!!!!!
            /*
            5.class  xxx implements A{
             @Override
            public void say() {
                System.out.println("tiger叫唤...");
                }
            }
            6.jdk 底层创建匿名内部类，Outer04$1,立即创建Outer04$1实例，并把地址返给tiger
             */

            @Override
            public void say() {
                System.out.println("tiger叫唤...");
            }
        };
        System.out.println(tiger.getClass());
        tiger.say();


        //7.基于类的匿名内部类
        A fa = new A() {
            //8.编译类型为A，运行类型Outer04$2
            @Override
            public void say() {
                System.out.println("fa在叫唤...");
            }
        };
        System.out.println(fa.getClass());
        fa.say();

        //9.同时返回匿名内部类Outer04$的对象
        Father father = new Father("王");
        father.test();

        //10基于抽象类的匿名内部类
        Animal animal =  new Animal(){
            @Override
            void eat() {
                System.out.println("吃...");
            }
        };
        animal.eat();
    }
}

interface A {//接口
    public void say();
}

//class Tiger implements A{
//
//    @Override
//    public void say() {
//        System.out.println("tiger叫唤...");
//
//    }
//}
class Father {
    public void test(){
        System.out.println("test()方法被调用...");
    }
    public Father(String name){
    }
}
abstract class Animal{
    abstract void eat();
}